﻿<!DOCTYPE HTML>
<html>
<head>
    <script id="allmobilize" charset="utf-8" src="style/js/allmobilize.min.js"></script>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="alternate" media="handheld"/>
    <!-- end 云适配 -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>登录-纽约第一人民医院</title>
    <meta property="qc:admins" content="23635710066417756375"/>
    <meta name="baidu-site-verification" content="QIQ6KC1oZ6"/>

    <!-- <div class="web_root"  style="display:none">h</div> -->
    <script type="text/javascript">
        var ctx = "h";
        console.log(1);
    </script>
    <link rel="Shortcut Icon" href="h/images/favicon.ico">
    <link rel="stylesheet" type="text/css" href="style/css/style.css"/>

    <script src="style/js/jquery.1.10.1.min.js" type="text/javascript"></script>

    <script type="text/javascript" src="style/js/jquery.lib.min.js"></script>
    <script type="text/javascript" src="style/js/core.min.js"></script>


    <script type="text/javascript">
        var youdao_conv_id = 271546;
    </script>
    <script type="text/javascript" src="style/js/conv.js"></script>
</head>

<body id="login_bg">
<div class="login_wrapper">
    <div class="login_header">
        <a href="index.html"><img src="style/images/leader_default.png" width="100" height="100" alt="登录页"/></a>
        <div id="cloud_s"><img src="style/images/cloud_s.png" width="81" height="52" alt="cloud"/></div>
        <div id="cloud_m"><img src="style/images/cloud_m.png" width="136" height="95" alt="cloud"/></div>
    </div>

    <input type="hidden" id="resubmitToken" value=""/>
    <div class="navi">
        <ul>
            <li id="passwordLi" style="cursor: pointer;color: yellow"  onclick="changePage('1')">使用密码登录</li>
            <li id="codeLi"  onclick="changePage('2')" style="cursor: pointer;color: white; border-bottom: 3px solid rgb(255, 160, 10);">使用验证码登录</li>
        </ul>
    </div>
    <div class="login_box" style="display: block" id="byPassword">
        <form id="loginForm" action="index.html" >
            <input type="text" id="phone" name="phone" value="" tabindex="2" placeholder="请输入您的手机号码"/>
            <input type="password" id="password" name="password" tabindex="2" placeholder="请输入密码"/>
            <span class="error" style="display:none;" id="beError"></span>
            <label class="fl" for="remember"><input type="checkbox" id="remember" value="" checked="checked"
                                                    name="autoLogin"/> 记住我</label>
            <a href="reset.html" class="fr" target="_blank">忘记密码？</a>

            <input type="submit" id="submitLogin" value="登 &nbsp; &nbsp; 录"/>
            <!--				<a style="color:#fff;" href="index.html" class="submitLogin" title="登 &nbsp; &nbsp; 录"/>登 &nbsp; &nbsp; 录</a>-->
        </form>
        <div class="login_right">
            <div>还没有帐号？</div>
            <a href="register.html" class="registor_now">立即注册</a>
            <!--			    <div class="login_others">使用以下帐号直接登录:</div>-->
            <!--			    <a  href="h/ologin/auth/sina.html"  target="_blank" class="icon_wb" title="使用新浪微博帐号登录"></a>-->
            <!--			    <a  href="h/ologin/auth/qq.html"  class="icon_qq" target="_blank" title="使用腾讯QQ帐号登录"></a>-->
        </div>
    </div>

<!--    测试两种登录方式-->
    <div class="login_box" style="display: none" id="byCode">
        <form id="loginByCodeForm"  >
            <input type="text" id="phone2" name="phone" value="" tabindex="2" placeholder="请输入您的手机号码"/>
            <input type="text" id="code" name="code" tabindex="2" placeholder="请输入验证码"/>
            <span class="error" style="display:none;" id="beError1"></span>
            <button  id="sendCodeButton" type="button" onclick="sendCode()">发送验证码</button>


            <input type="button" id="submitLoginByCode" class="submitLogin" value="登 &nbsp; &nbsp; 录"/>
            <!--				<a style="color:#fff;" href="index.html" class="submitLogin" title="登 &nbsp; &nbsp; 录"/>登 &nbsp; &nbsp; 录</a>-->
        </form>
        <div class="login_right" style="float: right">
            <div>还没有帐号？</div>
            <a href="register.html" class="registor_now">立即注册</a>
        </div>
    </div>



    <div class="login_box_btm"></div>
</div>

<script type="text/javascript">
    $(function () {
        //查验手机号是否存在
        jQuery.validator.addMethod("validatePhone", function (value, element) {
            let flag = false;//初始默认值
            $.ajax({
                async: false,//同步请求
                type: "get",
                url: "/patient/existOfPhone",
                data: {
                    phone: value
                },
                dataType: "json"  //bug point : no comma
            }).done((result) => {
                flag = result.data;//true表明号码存在，false表明不存在，不能用于登录
            }).fail(() => {
                alert("查验手机号码存在失败");
            });
            return flag;
        }, "该手机号码尚未注册，请正确填写或前往注册");

        //验证表单
        $("#loginForm").validate({

            rules: {
                phone: {
                    required: true,
                    validatePhone: true
                },
                password: {
                    required: true,
                    rangelength: [6, 16]
                }
            },
            messages: {
                phone: {
                    required: "请输入手机号码"
                },
                password: {
                    required: "请输入密码",
                    rangelength: "密码长度为6到16位"
                }
            },
            submitHandler: function (form) {
                if ($("#remember").prop("checked")) {
                    $("#remember").val(1);
                } else {
                    $("#remember").val(null);
                }
                var phone = $("#phone").val();
                var password = $("#password").val();
                var remember = $("#remember").val();

                $(form).find(":submit").attr("disabled", true);
                $.ajax({
                    type: "post",
                    url: "/patient/login",
                    data: {phone: phone, password: password},
                }).done(function (result) {
                    if (result.data != null) {
                        if (remember == 1) {
                            localStorage.setItem("rememberMe", phone + "=" + password);
                        } else {
                            localStorage.removeItem("rememberMe");
                        }
                        //前往首页
                        location.href = "index.html";
                    } else {
                        alert(result.message);
                    }
                    $(form).find(":submit").attr("disabled", false);
                });
            }
        });

        //如果有记住密码，进入页面自动填充
        let rememberMe = localStorage.getItem("rememberMe");
        if (rememberMe != null) {
            let vs = rememberMe.split("=");
            $("#phone").val(vs[0]);
            $("#password").val(vs[1]);
            $("input[name=autoLogin]").prop("checked", true);
        }

        //焦点事件
        $("#phone").on("input", function () {
            //清除密码框内容并设置记住密码为未选中
            $("#password").val("");
            $("input[name=autoLogin]").prop("checked", false);

            //
            let rememberMe = localStorage.getItem("rememberMe");
            if (rememberMe != null) {
                let inputPhoneNumber = $(this).val();
                let vs = rememberMe.split("=");
                if (inputPhoneNumber == vs[0]) {
                    $("input[name='password']").val(vs[1]);
                    $("input[name='autoLogin']").prop("checked", true);
                }
            }
        })
    })
</script>
<script>
    let codeFlag=false;
    function sendCode(){
        //查验手机号是否存在
        $.ajax({
            async:false,
            url:"/patient/existOfPhone",
            type:"get",
            data:{
                phone:$("#phone2").val()
            }
        }).done((result)=>{
            if(result.data==true){
                $.ajax({
                    async:false,
                    url:"/code/send",
                    type:"get",
                    data:{phone:$("#phone2").val()}
                }).done((result)=>{
                    if(result.data==true){
                        codeFlag=true;
                        alert("短信发送成功，请注意查看接收，两分钟后失效");
                    }else {
                        alert("短信发送失败，请检查！");
                    }
                })
            }else {
                alert("该号码未注册，请先前往注册！");
            }
        });

    }

    $("#submitLoginByCode").click(function () {
        if(codeFlag==true){
            $.getJSON("/code/loginByCode",{phone:$("#phone2").val(),code:$("#code").val()},function (result) {
                if(result.data==true){
                    alert("登录成功！");
                    location.href="index.html";
                }else {
                    alert(result.message);
                }
            });
        }else {
            alert("未发送验证码");
        }
    });




    function changePage(val){
        if(val=="1"){
            $("#byPassword").show();
            $("#byCode").hide();
            $("#passwordLi").css("color","yellow");
            $("#codeLi").css("color","white");
        }else{
            $("#byPassword").hide();
            $("#byCode").show();
            $("#passwordLi").css("color","white");
            $("#codeLi").css("color","yellow");
        }
    }




</script>
</body>
</html>